project(FPMS)
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE "Release")
set(BUILD_USE_64BITS on)
set(platform x64)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    set(system linux)
    set(THIRDPARTY "/home/vmns/thirdparty/Linux")
    set(BOOST_DATE_TIME_LIB libboost_date_time.a)
    set(BOOST_THREAD_LIB libboost_thread.a)
    set(BOOST_FILESYSTEM_LIB libboost_filesystem.a)
    set(OXF_LIB oxf.a)
    set(RUTIL_LIB librutil.a)
    set(JSONCPP_LIB libjsoncpp.a)
    set(FSWATCH_LIB libfswatch.a)
    set(S_HTTPSERVER_LIB libS_HttpServer.a)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
    set(system win)
    set(THIRDPARTY "D:/work/projects/3rdparty")
    set(BOOST_DATE_TIME_LIB libboost_date_time-vc141-mt-s-x64-1_72.lib)
    set(BOOST_THREAD_LIB libboost_thread-vc141-mt-s-x64-1_72.lib)
    set(BOOST_FILESYSTEM_LIB libboost_filesystem-vc141-mt-s-x64-1_72.lib)
    set(GETOPT_LIB getopt-mt.lib)
    set(OXF_LIB oxf.lib)
    set(RUTIL_LIB rutil-mt.lib)
    set(JSONCPP_LIB libjson-mt.lib)
    set(FSWATCH_LIB libfswatch.lib)
    set(S_HTTPSERVER_LIB S_HttpServer.lib)
    set(MYSQL_LIB libmysql.lib)
    set(AF_LIB libarcsoft_face_engine.lib)
    set(OPENCV_CORE_LIB opencv_core249d.lib)
    set(OPENCV_HIGHGUI_LIB opencv_highgui249d.lib)
    set(OPENCV_IMGPROC_LIB opencv_imgproc249d.lib)
endif ()

#加载自定义模块
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if (${CMAKE_BUILD_TYPE} MATCHES "Release")
    message(STATUS "Release版本")
    set(BuildType "Release")
else ()
    set(BuildType "Debug")
    message(STATUS "Debug版本")
endif ()

#设置bin和lib库目录
set(RELEASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release)
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType})
    SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType})
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
    SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
    SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
endif ()

LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})

set(iLPR_Root ${CMAKE_CURRENT_SOURCE_DIR}/src)

INCLUDE_DIRECTORIES(${iLPR_Root})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/server)

#set(LINK_LIB_LIST oxf)

#s_http
set (S_HTTP_ROOT_PATH ${THIRDPARTY}/S_Http)
set (S_HTTP_INCLUDE_PATH ${S_HTTP_ROOT_PATH}/include)
set (S_HTTP_LIB_PATH ${S_HTTP_ROOT_PATH}/lib/${system}/${platform})
INCLUDE_DIRECTORIES(${S_HTTP_INCLUDE_PATH})
link_directories(${S_HTTP_LIB_PATH})
list(APPEND LINK_LIB_LIST ${S_HTTPSERVER_LIB})

#oxf
set(OXF_ROOT_PATH "${THIRDPARTY}/oxf")
set(OXF_INCLUDE_PATH "${OXF_ROOT_PATH}/include")
set(OXF_LIB_PATH "${OXF_ROOT_PATH}/lib/${system}/${platform}")
INCLUDE_DIRECTORIES("${OXF_INCLUDE_PATH}")
link_directories(${OXF_LIB_PATH})
list(APPEND LINK_LIB_LIST ${OXF_LIB})

#boost
set(BOOST_ROOT_PATH ${THIRDPARTY}/boost)
set(BOOST_INCLUDE_PATH ${BOOST_ROOT_PATH}/include)
set(BOOST_LIB_PATH ${BOOST_ROOT_PATH}/lib/${system}/${platform})
INCLUDE_DIRECTORIES(${BOOST_INCLUDE_PATH})
link_directories(${BOOST_LIB_PATH})
list(APPEND LINK_LIB_LIST ${BOOST_DATE_TIME_LIB} ${BOOST_THREAD_LIB} ${BOOST_FILESYSTEM_LIB})

#getopt
if (WIN32)
    set(GETOPT_ROOT_PATH "${THIRDPARTY}/getopt")
    set(GETOPT_INCLUDE_PATH "${GETOPT_ROOT_PATH}/include")
    set(GETOPT_LIB_PATH "${GETOPT_ROOT_PATH}/lib/${platform}")
    INCLUDE_DIRECTORIES("${GETOPT_INCLUDE_PATH}")
    link_directories(${GETOPT_LIB_PATH})
    list(APPEND LINK_LIB_LIST ${GETOPT_LIB})
endif (WIN32)

if (UINX)
    set(GETOPT_ROOT_PATH "${THIRDPARTY}/getopt")
    set(GETOPT_INCLUDE_PATH "${GETOPT_ROOT_PATH}/include")
    set(GETOPT_LIB_PATH "${GETOPT_ROOT_PATH}/lib/${system}/${platform}")
    INCLUDE_DIRECTORIES("${GETOPT_INCLUDE_PATH}")
    link_directories(${GETOPT_LIB_PATH})
    list(APPEND LINK_LIB_LIST ${GETOPT_LIB})
endif (UINX)

#mysql
if (WIN32)
    set(MYSQL_ROOT_PATH "${THIRDPARTY}/Mysql")
    set(MYSQL_INCLUDE_PATH "${MYSQL_ROOT_PATH}/include")
    LINK_DIRECTORIES("${MYSQL_ROOT_PATH}/lib/${system}/${platform}")
    INCLUDE_DIRECTORIES("${MYSQL_INCLUDE_PATH}")
    list(APPEND LINK_LIB_LIST ${MYSQL_LIB})
else (WIN32)
    LINK_DIRECTORIES("/usr/lib64/mysql")
endif (WIN32)

#jsoncpp
set (JSONCPP_ROOT_PATH ${THIRDPARTY}/jsoncpp)
set (JSONCPP_INCLUDE_PATH ${JSONCPP_ROOT_PATH}/include)
set (JSONCPP_LIB_PATH ${JSONCPP_ROOT_PATH}/lib/${system}/${platform})
INCLUDE_DIRECTORIES(${JSONCPP_INCLUDE_PATH})
link_directories(${JSONCPP_LIB_PATH})
list(APPEND LINK_LIB_LIST ${JSONCPP_LIB})

#af
set (AF_ROOT_PATH ${THIRDPARTY}/AF)
set (AF_INCLUDE_PATH ${AF_ROOT_PATH}/include)
set (AF_LIB_PATH ${AF_ROOT_PATH}/lib/${system}/${platform})
INCLUDE_DIRECTORIES(${AF_INCLUDE_PATH})
link_directories(${AF_LIB_PATH})
list(APPEND LINK_LIB_LIST ${AF_LIB})

#opencv
set (OPENCV_ROOT_PATH ${THIRDPARTY}/opencv)
set (OPENCV_INCLUDE_PATH ${OPENCV_ROOT_PATH}/include)
set (OPENCV_LIB_PATH ${OPENCV_ROOT_PATH}/lib/${system}/${platform})
INCLUDE_DIRECTORIES(${OPENCV_INCLUDE_PATH})
link_directories(${OPENCV_LIB_PATH})
list(APPEND LINK_LIB_LIST ${OPENCV_CORE_LIB} ${OPENCV_HIGHGUI_LIB} ${OPENCV_IMGPROC_LIB})

#resip
set(RESIP_ROOT_PATH "${THIRDPARTY}/resip")
set(RESIP_INCLUDE_PATH "${RESIP_ROOT_PATH}/include")
set(RESIP_LIB_PATH ${RESIP_ROOT_PATH}/lib/${system}/${platform})
INCLUDE_DIRECTORIES("${RESIP_INCLUDE_PATH}")
link_directories(${RESIP_LIB_PATH})
list(APPEND LINK_LIB_LIST ${RUTIL_LIB})

if (WIN32)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  /Zc:sizedDealloc- /MP /wd4430")
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} /MTd /Od /ZI")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} /MT /O2")
else (WIN32)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fpermissive")
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g -ggdb")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3")
endif (WIN32)

if (WIN32)
    #防止Windows.h包含Winsock.h
    add_definitions(-DWIN32_LEAN_AND_MEAN)
    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()

#add_definitions(-DUnicode)
add_definitions(-DS_HTTP_SERVER_USE_STATIC_LIB)

file(GLOB iLPR_Src_List ${iLPR_Root}/*/*.cpp ${iLPR_Root}/*/*.h ${iLPR_Root}/*/*.c)

file(GLOB iLPR_Lpr_List )

if (WIN32)
    file(GLOB iLPR_Lpr_List ${iLPR_Root}/lpr/lpr-win/*/*.cpp ${iLPR_Root}/lpr/lpr-win/*/*.h ${iLPR_Root}/lpr/lpr-win/*/*.c)
else(WIN32)
    file(GLOB iLPR_Lpr_List ${iLPR_Root}/lpr/lpr-linux/*/*.cpp ${iLPR_Root}/lpr/lpr-linux/*/*.h ${iLPR_Root}/lpr/lpr-linux/*/*.c)
endif(WIN32)
#add_library(oxf STATIC ${oxf_src_list})

add_subdirectory(server)
